package com.qfedu.config;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;

/**
 * @Component  向容器中加入bean ApplicationContextHolder
 * implements ApplicationContextAware  该接口的作用就是  再创建bean 时会将容器的核心实现ApplicationContext applicationContext 注入进来
 *
 *          setApplicationContext(ApplicationContext applicationContext)
 *
 *
 */
@Component
public class ApplicationContextHolder implements ApplicationContextAware {

    // 静态的变量 整个类共享
    public static  ApplicationContext applicationContext;


    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {

        // 让整个类持有应用上下文  applicationContext
        ApplicationContextHolder.applicationContext = applicationContext;
    }


    /**
     * 获取应用上下文
     * @return
     */
    public static ApplicationContext getApplicationContext() {
        return applicationContext;
    }
}
